(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "maishu-jueying", "react", "./base-component", "maishu-services-sdk", "controls/image-manager", "maishu-ui-toolkit"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const maishu_jueying_1 = require("maishu-jueying");
    const React = require("react");
    const base_component_1 = require("./base-component");
    const maishu_services_sdk_1 = require("maishu-services-sdk");
    const image_manager_1 = require("controls/image-manager");
    const ui = require("maishu-ui-toolkit");
    function checkbox(text) {
        return class extends maishu_jueying_1.PropEditor {
            render() {
                let { value } = this.props;
                return React.createElement(React.Fragment, null,
                    React.createElement("input", { type: "checkbox", ref: (e) => {
                            if (!e)
                                return;
                            e.checked = value;
                            e.onchange = () => {
                                this.props.updateComponentProp(e.checked);
                            };
                        } }),
                    React.createElement("span", { style: { paddingLeft: 6 } }, text));
            }
        };
    }
    exports.checkbox = checkbox;
    function toggle(options) {
        options = Object.assign({ defaultValue: false }, options || {});
        return class extends maishu_jueying_1.PropEditor {
            render() {
                let { value } = this.props;
                value = value == null ? options.defaultValue : value;
                return React.createElement("label", { className: "pull-left switch" },
                    React.createElement("input", { type: "checkbox", className: "ace ace-switch ace-switch-5", checked: value, onChange: e => {
                            this.props.updateComponentProp(e.target.checked);
                        } }),
                    React.createElement("span", { className: "lbl middle" }));
            }
        };
    }
    exports.toggle = toggle;
    function numberInput() {
        return class extends maishu_jueying_1.PropEditor {
            render() {
                let { value } = this.props;
                return React.createElement("input", { className: "form-control", ref: e => {
                        if (!e)
                            return;
                        e.value = value == null ? "" : `${value}`;
                        e.onchange = event => {
                            let floatRegex = /\-?\d+\.\d+/g;
                            let intRegex = /\-?\d+/g;
                            if (floatRegex.test(e.value)) {
                                value = parseFloat(e.value);
                                this.props.updateComponentProp(value);
                            }
                            else if (intRegex.test(e.value)) {
                                value = parseInt(e.value);
                                this.props.updateComponentProp(value);
                            }
                        };
                    } });
            }
        };
    }
    exports.numberInput = numberInput;
    function image(text, maxWidth) {
        return class extends maishu_jueying_1.PropEditor {
            constructor(props) {
                super(props);
                this.imageService = base_component_1.createService(maishu_services_sdk_1.ImageService);
            }
            render() {
                let imagePath = this.props.value;
                return React.createElement("img", { className: "img-responsive", title: text, style: { maxWidth }, src: imagePath ? this.imageService.imageSource(imagePath) : null, ref: (e) => {
                        if (!e)
                            return;
                        let size = maxWidth || 200;
                        ui.renderImage(e, { imageSize: { width: size, height: size } });
                        e.onclick = () => {
                            image_manager_1.default.show((imageIds) => {
                                // store.ImagePath = imageIds[0];
                                // this.setState(this.state);
                                this.props.updateComponentProp(imageIds[0]);
                            });
                        };
                    } });
            }
        };
    }
    exports.image = image;
});
